var DataTypeList = {
	"101": [{
		"name": "地表裂缝计",
		"jcdw": "mm(毫米) ",
		"column": "JCSJ101A030",
		"zbbm": "value"
	}],
	"102": [{
		"name": "墙裂缝计",
		"jcdw": "mm(毫米) ",
		"column": "JCSJ102A030",
		"zbbm": "value"
	}],
	"103": [{
		"name": "加速度计",
		"jcdw": "°(度)",
		"column": "JCSJ103A030",
		"zbbm": "X"
	}, {
		"name": "加速度计",
		"jcdw": "°(度)",
		"column": "JCSJ103A031",
		"zbbm": "Y"
	}, {
		"name": "加速度计",
		"jcdw": "°(度)",
		"column": "JCSJ103A032",
		"zbbm": "Z"
	}, {
		"name": "加速度计",
		"jcdw": "mg(加速度值)",
		"column": "JCSJ103A033",
		"zbbm": "gX"
	}, {
		"name": "加速度计",
		"jcdw": "mg(加速度值)",
		"column": "JCSJ103A034",
		"zbbm": "gY"
	}, {
		"name": "加速度计",
		"jcdw": "mg(加速度值)",
		"column": "JCSJ103A035",
		"zbbm": "gZ"
	}],
	"104": [{
		"name": "泥位计",
		"jcdw": "m(米)",
		"column": "JCSJ104A030",
		"zbbm": "value"
	}],
	"105": [{
		"name": "预警喇叭"
	}],
	"106": [{
		"name": "微芯桩",
		"jcdw": "°(度)",
		"column": "JCSJ106A030",
		"zbbm": "angle"
	}, {
		"name": "微芯桩",
		"jcdw": "°(度)",
		"column": "JCSJ106A031",
		"zbbm": "trend"
	}, {
		"name": "微芯桩",
		"jcdw": "mg(加速度值)",
		"column": "JCSJ106A032",
		"zbbm": "glmpact"
	}, {
		"name": "微芯桩",
		"jcdw": "mg(加速度值)",
		"column": "JCSJ106A033",
		"zbbm": "gX"
	}, {
		"name": "微芯桩",
		"jcdw": "mg(加速度值)",
		"column": "JCSJ106A034",
		"zbbm": "gY"
	}, {
		"name": "微芯桩",
		"jcdw": "mg(加速度值)",
		"column": "JCSJ106A035",
		"zbbm": "gZ"
	}],
	"201": [{
		"name": "雨量计",
		"jcdw": "mm(毫米)雨量",
		"column": "JCSJ201A030",
		"zbbm": "value"
	}],
	"201sum": [{
		"name": "累计雨量计",
		"jcdw": "mm(毫米)雨量",
		"column": "JCSJ201A030",
		"zbbm": "value"
	}],
	"202": [{
		"name": "土壤含水率",
		"jcdw": "%(百分比)",
		"column": "JCSJ202A030",
		"zbbm": "value"
	}],
	"203": [{
		"name": "裂缝计",
		"jcdw": "mm(毫米)",
		"column": "JCSJ203A030",
		"zbbm": "value"
	}],
	"204": [{
		"name": "X位移值",
		"jcdw": "mm(毫米)",
		"column": "JCSJ204A030",
		"zbbm": "X"
	}, {
		"name": "Y位移值",
		"jcdw": "mm(毫米)",
		"column": "JCSJ204A031",
		"zbbm": "Y"
	}, {
		"name": "Z位移值",
		"jcdw": "mm(毫米)",
		"column": "JCSJ204A032",
		"zbbm": "Z"
	}, {
		"name": "XYZ位移值",
		"jcdw": "mm(毫米)",
		"column": "JCSJ204A033",
		"zbbm": "XYZ"
	}, {
		"name": "XY位移值",
		"jcdw": "mm(毫米)",
		"column": "JCSJ204A034",
		"zbbm": "XY"
	}],
	"205": [{
		"name": "GNSS"
	}],
	"206": [{
		"name": "倾角计",
		"jcdw": "°(度)",
		"column": "JCSJ206A030",
		"zbbm": "X"
	}, {
		"name": "倾角计",
		"jcdw": "°(度)",
		"column": "JCSJ206A031",
		"zbbm": "Y"
	}, {
		"name": "倾角计",
		"jcdw": "°(度)",
		"column": "JCSJ206A032",
		"zbbm": "Z"
	}],
	"207": [{
		"name": "水压力",
		"jcdw": "kPa(千帕)",
		"column": "JCSJ207A030",
		"zbbm": "value"
	}, {
		"name": "水压力",
		"jcdw": "℃(摄氏度)",
		"column": "JCSJ207A031",
		"zbbm": "temp"
	}],
	"208": [{
		"name": "次声",
		"jcdw": "Hz(赫兹)",
		"column": "JCSJ208A030",
		"zbbm": "value"
	}],
	"209": [{
		"name": "土压力计",
		"jcdw": "kPa(千帕)",
		"column": "JCSJ209A030",
		"zbbm": "value"
	}],
	"210": [{
		"name": "振弦式应力计",
		"jcdw": "kN(千牛)",
		"column": "JCSJ210A030",
		"zbbm": "value"
	}],
	"211": [{
		"name": "地表位移",
		"jcdw": "mm(毫米)",
		"column": "JCSJ211A030",
		"zbbm": "value"
	}],
	"212": [{
		"name": "深部位移",
		"jcdw": "mm(毫米)",
		"column": "JCSJ212A030",
		"zbbm": "X"
	}, {
		"name": "深部位移",
		"jcdw": "mm(毫米)",
		"column": "JCSJ212A031",
		"zbbm": "Y"
	}, {
		"name": "深部位移",
		"jcdw": "mm(毫米)",
		"column": "JCSJ212A032",
		"zbbm": "Z"
	}],
	"213": [{
		"name": "倾斜仪",
		"jcdw": "mm(毫米)",
		"column": "JCSJ213A030",
		"zbbm": "value"
	}],
	"888": [{
		"name": "地下水水位温度",
		"jcdw": "℃(摄氏度)",
		"column": "JCSJ888A030",
		"zbbm": "Temp"
	}, {
		"name": "地下水水位深度",
		"jcdw": "m(米)",
		"column": "JCSJ888A031",
		"zbbm": "value"
	}, {
		"name": "地下水水位电导率",
		"jcdw": "mS/cm",
		"column": "JCSJ888A032",
		"zbbm": "value"
	}],
	"215": [{
		"name": "多点位移",
		"jcdw": "mm(毫米)",
		"column": "JCSJ215A030",
		"zbbm": "X"
	}, {
		"name": "多点位移",
		"jcdw": "mm(毫米)",
		"column": "JCSJ215A031",
		"zbbm": "Y"
	}, {
		"name": "多点位移",
		"jcdw": "mm(毫米)",
		"column": "JCSJ215A032",
		"zbbm": "Z"
	}],
	"216": [{
		"name": "渗压计",
		"jcdw": "kPa(千帕)",
		"column": "JCSJ216A030",
		"zbbm": "value"
	}],
	 "217": [{
		"name": "流速仪",
		"jcdw": "m/s(米/秒)",
		"column": "JCSJ217A030",
		"zbbm": "value"
	}],
	"218": [{
		"name": "气温",
		"jcdw": "℃(摄氏度)",
		"column": "JCSJ218A030",
		"zbbm": "value"
	}],
	"219": [{
		"name": "TDR变形计",
		"jcdw": "mm(毫米)",
		"column": "JCSJ219A030",
		"zbbm": "value"
	}],
	"220": [{
		"name": "泉水流量",
		"jcdw": "m/?s(立方米/秒)",
		"column": "JCSJ220A030",
		"zbbm": "value"
	}],
	"221": [{
		"name": "沉降仪",
		"jcdw": "mm(毫米)",
		"column": "JCSJ221A030",
		"zbbm": "value"
	}],
	"222": [{
		"name": "钻孔测斜仪",
		"jcdw": "mm(毫米)",
		"column": "JCSJ222A030",
		"zbbm": "X"
	}, {
		"name": "钻孔测斜仪",
		"jcdw": "mm(毫米)",
		"column": "JCSJ222A031",
		"zbbm": "Y"
	}],
	"223": [{
		"name": "土壤温度",
		"jcdw": "℃(摄氏度)",
		"column": "JCSJ223A030",
		"zbbm": "value"
	}],
	"224": [{
		"name": "倾角",
		"jcdw": "mm(毫米)",
		"column": "JCSJ224A030",
		"zbbm": "X"
	}, {
		"name": "倾角",
		"jcdw": "mm(毫米)",
		"column": "JCSJ224A031",
		"zbbm": "Y"
	}, {
		"name": "倾角",
		"jcdw": "mm(毫米)",
		"column": "JCSJ224A032",
		"zbbm": "Yaw"
	}],
	"225": [{
		"name": "地表水位",
		"jcdw": "m(米)",
		"column": "JCSJ225A030",
		"zbbm": "value"
	}],
	"900": [{
		"name": "视频监测"
	}]
};
var colors= ['#E5561F', '#7FBF7F', '#7F7FFF', '#FF6F10', '#8756D8', '#310F39', '#FF7F7F','#8FBC8F'];
var startTime=GetQueryString("startTime");
var endTime=GetQueryString("endTime");
var uniqure_code=GetQueryString("uniqure_code");

function getData(){
    if(uniqure_code !=null ){
		let url ;
		if(startTime &&endTime && uniqure_code){
			if(!ismonth(startTime) && !ismonth(endTime)){
				url ="http://192.168.9.59:801/apis/result/queryAlllist/?startTime=&endTime=&uniqure_code="+uniqure_code;
			}else{
				url ="http://192.168.9.59:801/apis/result/queryAlllist/?"+"startTime="+startTime+"&endTime="+endTime+"&uniqure_code="+uniqure_code;
			}

		}else if(uniqure_code){
		 url ="http://192.168.9.59:801/apis/result/queryAlllist/?"+"uniqure_code="+uniqure_code;
		}
		
		$.get(url, function (res) {
            if(res.msg=="success"){
                let data = res.data;
                if(data.length>0){
					let DataArr=[];
					debugger
                    data.forEach((li)=>{
						if(li.dataType !== "214"){
							if(li.data && li.data.length>0){
								let page;
								let pageArr;
								let list = Object.keys(DataTypeList);
								let indexNum=list.indexOf(li.dataType);
								if(indexNum>-1){
									if(DataTypeList[li.dataType].length>1){
										pageArr=DataTypeList[li.dataType];
										pageArr.forEach((line)=>{
											page = line;
											page.uniqure_code=li.uniqure_code;
											let column = li.column;
											let dataList=[];
											for(let a=0;a<li.data.length;a++){
												let sumi={}
												for(let b=0;b<column.length;b++){
														let key = column[b];
														sumi[column[b]]=li.data[a][b];
												}
												dataList.push(sumi)
											}
											page.data=dataList;
											DataArr.push(page)
										})
									}else{
										page = DataTypeList[li.dataType][0];
										page.uniqure_code=li.uniqure_code;
										let column = li.column;
										let dataList=[];
										for(let a=0;a<li.data.length;a++){
											let sumi={}
											for(let b=0;b<column.length;b++){
													let key = column[b];
													sumi[column[b]]=li.data[a][b];
											}
											dataList.push(sumi)
										}
										page.data=dataList;
										DataArr.push(page)
									}
								}
								
							}
						}
                    })
                    OrganizeData(DataArr)
                }else{
                    $("#EquipmentDiagram").html("<p style='text-align: center;height: 100px;line-height:100px;'>暂无数据</p>")
                }
               
            }
        })
    }else{
        layui.use(['layer'], function(){
            layer.msg('请传入设备code')
        })
        return;
    }
}
getData();
function OrganizeData(val){
    let TimeData=[];
    let yAxisData=[];
    let seriesData=[];
    val.forEach((item,index)=>{
        let arr=[];
        item.data.forEach((li)=>{
            if(index==0){TimeData.push(li.time);}  
            arr.push(li[item.column])
        })
        
        if(index == 0 ||index == 1||index == 2){
            yAxisData.push({
                title: {
                    text: item.name + item.jcdw,
                    style: {color:colors[index]}
                }
            })
        }else{
            yAxisData.push({
                title: {
                    text: item.name + item.jcdw,
                    style: {color:colors[index]}
                },
                opposite: true
            })
        }
        seriesData.push( {
            type: 'line',
            name: item.name,
            data:arr,
            yAxis:index
        })
    })

    let option={
    chart: {
            type: 'line',
            style: {fontFamily: "'Unica One', sans-serif"},
            plotBorderColor: '#606063',
            // zoomType: 'x',
            spacingTop: 20,
            spacingRight: 20,
            // height: 390
    },
    colors: ['#E5561F', '#7FBF7F', '#7F7FFF', '#FF6F10', '#8756D8', '#310F39', '#FF7F7F','#8FBC8F'],
    title: {text: '',enabled: false},
    credits: {enabled: false},
    exporting: {enabled: false},
    subtitle: {text: ''},
    xAxis: {
		categories: TimeData,
		tickInterval:100,
		labels: {
            enabled: true,
			formatter: function() {
				let arr = this.value.split(" ");
				if(arr[1]){
					return arr[1];
				}else{
					return this.value;
				}
				
            }
          }
    },
	yAxis: yAxisData,
	lang: { noData: "数据接收中..." },
	noData: { position: { align: 'center', verticalAlign: 'center' }, attr: { 'stroke-width': 1, stroke: '#EFEFEF' }, style: { fontSize: '14px', color: '#999', fontWeight: "normal" } },
    // tooltip: {
    //     // formatter: function () {
    //     //     debugger
    //     // }
    // },
    plotOptions: {
            spline: {
                lineWidth: 1,
                states: {hover: {lineWidth: 2}},
                marker: {enabled: false}
            }
    },
    series: seriesData
    }
    $("#EquipmentDiagram").highcharts(option);
}
function GetQueryString(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}
function ismonth(str) {
	for(ilen=0;ilen<str.length;ilen++){
		if(str.charAt(ilen) < '0' || str.charAt(ilen) > '9' ){if((str.charAt(ilen)!='-'))return false;} 
	}
	return true;
}